package corbaEventService;

import org.omg.CORBA.Object;
import org.omg.PortableServer.POAPackage.ServantNotActive;
import org.omg.PortableServer.POAPackage.WrongPolicy;

import cosEventChannelAdmin.ConsumerAdminPOA;
import cosEventChannelAdmin.EventChannel;
import cosEventChannelAdmin.ProxyPullSupplier;
import cosEventChannelAdmin.ProxyPushSupplier;
import cosEventChannelAdmin.ProxyPushSupplierHelper;


public class ConsumerAdminImpl extends ConsumerAdminPOA {
	private EventChannel channel;
	private ProxyPushSupplier proxyPushSupplier;
	
	
	public ConsumerAdminImpl(EventChannel channel) {
		super();
		this.channel = channel;
	}

	@Override
	public ProxyPushSupplier obtain_push_supplier() {
		initProxyPushSupplier();
		return proxyPushSupplier;
	}

	@Override
	public ProxyPullSupplier obtain_pull_supplier() {		
		return null;
	}
	
	private void initProxyPushSupplier(){
		if(proxyPushSupplier == null){
			ProxyPushSupplierImpl proxyPushSupplierImpl = new ProxyPushSupplierImpl(channel);
			Object ref = null;
			try {
				ref = _poa().servant_to_reference(proxyPushSupplierImpl);
			} catch (ServantNotActive e) {				
				e.printStackTrace();
			} catch (WrongPolicy e) {				
				e.printStackTrace();
			}
			proxyPushSupplier = ProxyPushSupplierHelper.narrow(ref);
		}
	}

}
